package com.example.springconfig;

import com.example.springconfig.demos.component.BeanLifeComponent;
import com.example.springconfig.demos.model.User;
import org.apache.catalina.core.ApplicationContext;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;

@SpringBootApplication
public class SpringConfigApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(SpringConfigApplication.class, args);
//        User user = context.getBean(User.class);
//        user.setName("lisi");
//        System.out.println(user);
//        // 打印 user对象的内存地址
//        System.out.println("当前对象的地址: " + System.identityHashCode(user));
//
//        User user2 = context.getBean(User.class);
//        System.out.println(user2);
//        // 打印 user对象的内存地址
//        System.out.println("当前对象的地址: " + System.identityHashCode(user2));

        BeanLifeComponent lifeComponent = context.getBean(BeanLifeComponent.class);
        lifeComponent.use();
        // 有不手动点击结束进程的方式来执行destroy方法
        // ((AbstractApplicationContext)context).destroy();
   }
}
